<%@ page language="java" pageEncoding="UTF-8"%>
<%@include file="/pc/jsp/common/common.jsp"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdOrderDataClass"%>
<%@ page language="java" import="com.limao.DBDataClass.CrowdSysProjectClass"%>
<%
  String orderidStr=request.getParameter("orderid"); 
  CrowdOrderDataClass obj=WebFunction.getCrowdOrderInfo(request, response, orderidStr);
  if(obj==null) return; 
  CrowdSysProjectClass pro=WebFunction.getProjectInfo(obj.projectid);

String btnStr = "";
        int state = -1;
        if (obj != null) {
            // state 订单状态(0 取消 1待付款 2已付款  3可申请发货  4已申请发货 5发货  6签收)
            state = CacheClass.getIntValue(obj.state);
             switch (state) {
                case 0:
                    btnStr = "";
                    break;
                case 1:
                    btnStr = "付款";
                    break;
                case 2:
                        btnStr = "";
                    break;
              
                case 5:
                        btnStr = "签收";
                    break;
                case 6:
                    btnStr = "";
                    break;
                default:
                    break;
            }
       }

    
%>

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
    <title>众筹订单信息</title>
    <script>
		$(window).load(function() {
			headertabcurrent=6;
			$("#header").load("pc/header.jsp"); 
			$("#footer").load("pc/footer.jsp"); 
		});
	</script>
</head>
<body  ontouchstart="">
    <div class="theme-popover-mask"></div>
    
        <!--header-->
	<div  id="header"> </div>

    <div class="container jz" style="margin-top: 18px;">
        <div class="w100 of" style="background: #fbfbfb">
            <div class="fqzcTittle jz tc c3 f25 of clearfix">
                订单信息
            </div>
            <%if(obj==null) return; %>
            <div class="orderDiv1 bcf jz">
                <div class="clearfix of" style="border-bottom: 1px dashed #E7E7E7;width: 694px;">
                    <img src="<%=(imgPath+pro.projectimage.split(";")[0])%>" class="fl">
                    <div class="fl">
                        <p class="c3 f21" style="margin-top: 17px;"><%=obj.projectname %></p>
                        <div style="margin-top: 13px;">
                            <p class="c9 f16 fl"><span class="f13">&yen;</span><span class="f20"><%=obj.packageprice %></span> ×<%=obj.ordernum %></p>
                            <p class="cred f16 fl" style="margin-left: 38px;"><span class="f13">&yen;</span><span class="f20"><%=obj.totalrmb %></span></p>
                        </div>
                    </div>
                </div>
                <div class="f16 c9 lh2">
                    <p class="lh15"><%=obj.intro %></p>
                    <p>数量：<span class="cred"><%=obj.ordernum %>件</span></p>
                    <p>代理期：购买时间后<span class="cred"><%=obj.days %>天。</span></p>
                    <p>普通快递：<span class="cred">免费</span></p>
                </div>
            </div>

            <div  class="orderDiv2 jz">
                <div class="f16 c9">
                    <p class="mgt20">订单编号：<%=obj.order_sn %><span class="dib" style="width: 140px;"></span>当前状态：<span class="cred"><%=obj.stateAbout %></span></p>
                    <p class="mgt20">购买日期：<%=obj.starttimeAbout %><span class="dib" style="width: 140px;"></span><%=obj.days %>天<span class="dib" style="width: 140px;"></span>支付方式：<%=obj.paytypeAbout %></p>
                    <%if(!CacheClass.isEmpty(obj.address)) {%>
	                    <p class="mgt20">收货地址：<%=obj.address.split("_")[0] %></p>
	                    <p class="mgt20">收件人：<%=obj.address.split("_")[1] %></p>
	                    <p class="mgt20">联系电话：<%=obj.address.split("_")[2] %></p>
                    <%} else{%>
	                    <p class="mgt20">收货地址：</p>
	                    <p class="mgt20">收件人：</p>
	                    <p class="mgt20">联系电话：</p>                  
                    <%} %>
                    <div class="clearfix of mgt20">
                       <div class="fl">
                           <p class="lh2">供应商：</p>
                       </div>
                        <div class="fl">
                            <p class="lh2">名称：<%=obj.companyname %></p>
                            <p class="lh2">地址：<%=obj.compaddress %></p>
                            <p class="lh2">联系：<%=obj.qq %></p>
                        </div>
                    </div>
                    <p class="mgt20">物流信息：<%if(!CacheClass.isEmpty(obj.courier_sn)){ %><a href="<%=obj.courier_url%>"><span style="color: #0374f3"><%=obj.courier_sn%></span></a><%} %></p>
                </div>
            </div>
            <div  class="orderDiv2 jz" style="border: none">
            	<input type="button" name="" value="取消" onclick="btnCancelEvent(<%=obj.orderid %>)" id="btncancel" class="bcblue cf f27 tc db br3 cursor" style="width: 350px;height: 63px;line-height: 62px;"/>
                <input type="button" name="" value="<%=btnStr %>" onclick="btnConfirmEvent(<%=obj.orderid %>)" id="btnconfirm" class="bcblue cf f27 tc db br3 cursor" style="width: 350px;height: 63px;line-height: 62px;"/>
            </div>
            
            
            
        </div>

    </div><!--container-->

	<!--footer-->
    <div id="footer" class="footer w100 of"></div>

<div id="loadingfDiv" class="loadingfDiv pf w100 h100 db">
    <div class="w100 h100">
        <img src="pc/images/loading.gif" class="db jz" style="margin-top: 40%;">
    </div>
</div><!--loadinfDiv-->
<script>

    var state = <%=state%>;
    function judgeShowBtn() {
        if (state == -1) {
            return;
        }
        // 判断确定按钮是否显示
         // state 订单状态(0 取消 1待付款 2已付款  5发货  6签收)
        
        if (state * 1.0 == 1 || state * 1.0 == 2 || state * 1.0 == 5 || state * 1.0 == 6) 
        {
           if (state*1.0 == 1) { // 是否显示取消按钮
                $("#btncancel").show();
                $("#btnconfirm").show();
            } else if(state * 1.0 == 2 || state * 1.0 == 6){
            	$("#btncancel").hide();
                $("#btnconfirm").hide();
            }else {
                $("#btncancel").hide();
                $("#btnconfirm").show();
            }
        } else {
            $("#btncancel").hide();
            $("#btnconfirm").hide();
        }
        
    }
    
    /**
     * 取消
     */
    function btnCancelEvent(orderidVal) {
        if (state == 1) {
	       layer.confirm('您确定取消订单？', {
	  			btn: ['确定','取消'] //按钮
				}, function(){
					cancelO(orderidVal);
				}, function(){
					
	  			}	
		    );
        }
    }

    var cancelO = function cancelOrder() {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m: 1721, orderid: <%=obj.orderid%>}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
            },
            success: function (data) {
                if (data.state == 1) {
                    layer.alert("取消成功！");

                    // 存储需要刷新订单列表界面
                    localStorage.setItem("needrefreshmycrowdFunding", 'true');

                    setTimeout(function () {                  history.back();
                    }, 500);
                } else {
                    layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
            }
        });
    }




    function btnConfirmEvent(orderidVal) {
        if (state == 1) {
            payOrder(orderidVal);
        } else if (state == 5) {
        	confirmOrder(orderidVal);
            //applySendOrder(orderidVal);
        } /* else if (state == 7) {
            confirmOrder(orderidVal);
        } */
    }
    
    /**
     * 再次支付
     */
    function payOrder(orderidVal) {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m: 1722, orderid: orderidVal}),
            type: 'post',
            dataType: 'json',
            contentType: "application/json;charset=utf-8",
            beforeSend: function () {
                  $("#loadingfDiv").fadeIn();
            },
            success: function (data) {
                if (data.state == 1) {

                    // TODO: 再次支付
                    console.log("支付参数：" + data.params);

                } else {
                    layer.alert(data.info);
                }
            },
            error: function (data) {
                layer.alert(data.info);
            },
            complete: function () {
                 $("#loadingfDiv").fadeOut();
            }
        });
    } 
    
    /**
     * 申请发货
     */
/*     function applySendOrder(orderidVal) {
        // 发货申请 跳转到填写地址页面
        window.location.href=baseUrl+"pc/myAddress.jsp?orderidlist="+orderidVal;
    } */
    
    /**
     * 确认收货
     */    
    function confirmOrder(orderidVal) {
        $.ajax({
            url: "PlugServlet ",
            data: JSON.stringify({m:1617,orderid :orderidVal}),
            type: 'post',
            dataType: 'json',
            contentType:"application/json;charset=utf-8",
            beforeSend: function () {
                $("#loadingfDiv").fadeIn();
            },
            success: function (data) {
            	console.log(data);
   	           if(data['state']==1)
	           {
	           		layer.alert(data.info);
	           }
	           else
	           {
	           		layer.alert(data.info);
	           }
           },
            error: function (data) {
                layer.alert(data.msg);
                return false;
            },
            complete: function () {
                $("#loadingfDiv").fadeOut();
            }
        });
    }

 judgeShowBtn();
 
</script>
</body>
</html>